package com.itheima.d4_byte__stream;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

public class FileInputStreamTest2 {
    public static void main(String[] args) throws Exception {
        //创建文件字节输入流管道
        InputStream fileInputStream = new FileInputStream("D:\\Java\\JavaEE_learn\\IO_learn\\src\\main\\java\\com\\itheima\\itheima02.txt");

        //2.开始读取文件中的数据，每次读取多个字节
        //public int read(byte b[], int off, int len) throws IOException
        //没次读取多个字节到字节数组中返回的读取字节数量，读取完毕返回-1；
//        byte[] bytes = new byte[3];
//        int read = fileInputStream.read(bytes);
//        String s = new String(bytes);
//        System.out.println(s);
//        System.out.println("当前读取的字节数量：" +read);
//
//        int len2=  fileInputStream.read(bytes);
//        String re2 = new String(bytes,0,len2);
//        System.out.println(re2);
//        System.out.println("当前读取的字节数量：" +len2);


        byte[] buffer = new byte[3];
        int len;
        while ((len =fileInputStream.read(buffer)) != -1){
            //读多少取多少
            String rs = new String(buffer , 0, len);
            System.out.print(rs);
        }
        //读取的汉字会乱码
        //流使用完毕之后，必须关闭，释放资源
        fileInputStream.close();
    }
}
